package com.smartboot.plus.wapper;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.smartboot.plus.ignite.cache.MqttAuthCache;
import com.smartboot.plus.support.BaseMqttEntityWrapper;
import com.smartboot.plus.utils.Func;
import com.smartboot.plus.vo.MqttAuthCacheVO;

public class MqttAuthWrapper extends BaseMqttEntityWrapper<MqttAuthCache, MqttAuthCacheVO> {

    public static MqttAuthWrapper build() {
        return new MqttAuthWrapper();
    }

    @Override
    public MqttAuthCacheVO entityVO(MqttAuthCache entity) {
        try {
            String json = JSON.toJSONString(entity);
            MqttAuthCacheVO mqttAuthCacheVO = JSONObject.parseObject(json, MqttAuthCacheVO.class);
            if (Func.isNotEmpty(mqttAuthCacheVO)) {
                mqttAuthCacheVO.setPassword("");
            }
            return mqttAuthCacheVO;

        } catch (Exception e) {
            return null;
        }
    }


}
